package com.yj.rabbitClient.etoq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.yj.rabbitClient.util.RabbitMQUtil;

import java.io.IOException;

public class Publisher {
    public static void main(String[] args) {
        Connection connection = RabbitMQUtil.getConnection();
        String exchangeName = "helloExchange";
        String queueName = "hello";
        Channel channel = null;
        try {
            channel = connection.createChannel();
//            channel.queueDeclare(queueName,false,false,false,null);
            channel.exchangeDeclare(exchangeName,"topic");
            for (int i = 0; i < 10 ; i++) {
                channel.basicPublish(exchangeName,"coffee",null,("发送第"+i+"条消息").getBytes());

            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                channel.close();
                connection.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
